1 00:00:01,210 --> 00:00:01,840 Hey there. 2 00:00:01,840 --> 00:00:07,720 In this lecture, we're going to be making a simple leaderboard that displays the kills, deaths, and 3 00:00:07,720 --> 00:00:10,120 money for every single player in our game. 4 00:00:10,120 --> 00:00:11,620 So let's get started. 5 00:00:12,200 --> 00:00:18,200 We can create a new script inside of the server script service, and I'm going to call this script my 6 00:00:18,200 --> 00:00:19,910 leaderboard handler. 7 00:00:21,230 --> 00:00:24,920 We're going to fill this in with the same comet template as before. 8 00:00:26,810 --> 00:00:31,220 And in order to set up a leaderboard for every single player, we're going to have to get the player 9 00:00:31,220 --> 00:00:31,970 service. 10 00:00:34,520 --> 00:00:38,510 And then we can go ahead and listen for when a player joins our game. 11 00:00:39,840 --> 00:00:40,980 Get that player. 12 00:00:40,980 --> 00:00:43,680 And here we can go ahead and set up a leaderboard forum. 13 00:00:43,680 --> 00:00:48,090 So we'll create a new folder that'll be instance dot new folder. 14 00:00:49,050 --> 00:00:52,890 And then the name of this folder will be our leader stats. 15 00:00:53,040 --> 00:00:57,030 And then we can go ahead and set the parent of the folder equal to our player. 16 00:00:57,920 --> 00:01:03,440 And then we want to create three different int values to represent the kills, deaths and how much money 17 00:01:03,440 --> 00:01:04,220 our player has. 18 00:01:04,220 --> 00:01:06,950 So we can go ahead and create a dedicated function for that. 19 00:01:09,190 --> 00:01:11,860 And we'll call this create int value. 20 00:01:12,160 --> 00:01:15,340 And we can pass the name for the int value. 21 00:01:15,610 --> 00:01:20,560 Um what value we would like to set in it by default as well as the parent for the int value. 22 00:01:20,650 --> 00:01:25,420 And inside of here we'll create a new variable I'll call it int and that's equal to instance dot new. 23 00:01:25,420 --> 00:01:27,550 Create a new int value instance. 24 00:01:27,550 --> 00:01:32,800 And then the name is going to be equal to the name pass to the function the value equal to the value, 25 00:01:32,800 --> 00:01:36,040 and then the parent equal to the parent. 26 00:01:36,040 --> 00:01:41,320 Then we can go ahead and call this function and create, for example, our kill's value. 27 00:01:41,350 --> 00:01:43,480 We'll start off with a default value of zero. 28 00:01:43,480 --> 00:01:46,630 And then the parent is going to be our leader stats folder. 29 00:01:47,050 --> 00:01:49,900 And then we can basically just copy this and do it two more times. 30 00:01:49,900 --> 00:01:56,230 But this time we want to have a value for our players deaths as well as for our players money. 31 00:01:57,170 --> 00:02:02,510 Now we're going to be filling in money and kills later when we add zombies to our game and we set up 32 00:02:02,510 --> 00:02:03,770 the shop for our game. 33 00:02:03,770 --> 00:02:08,630 But we can go ahead and implement the functionality for listening to a player's deaths. 34 00:02:08,630 --> 00:02:13,700 So when a player joins our game, what we can go ahead and do is we can listen for when a player has 35 00:02:13,700 --> 00:02:15,800 their character added to them. 36 00:02:15,860 --> 00:02:18,710 We'll connect a function, get that character. 37 00:02:19,700 --> 00:02:21,410 And then when that character dies. 38 00:02:21,410 --> 00:02:22,550 So character. 39 00:02:22,550 --> 00:02:26,450 And we'll get the humanoid and listen to its died event. 40 00:02:27,610 --> 00:02:34,060 The one we can go ahead and do is refer to the player, access their leader stats folder and inside 41 00:02:34,060 --> 00:02:35,080 of their leader stats folder. 42 00:02:35,080 --> 00:02:39,820 We can get deaths and then we can set the value plus equal to one. 43 00:02:40,660 --> 00:02:45,130 And just like that, we've already set up a basic leaderboard for all the players in our game and it 44 00:02:45,130 --> 00:02:47,110 should increment when our player dies. 45 00:02:47,110 --> 00:02:48,880 So let's go ahead and test that out. 46 00:02:51,680 --> 00:02:53,300 So we can hop into our game. 47 00:02:53,300 --> 00:02:55,880 There's our leaderboard for kills, deaths and money. 48 00:02:55,880 --> 00:03:01,280 And then if I go ahead and reset my character, as you can see, deaths incremented by one and then 49 00:03:01,280 --> 00:03:07,040 it'll stay there on my leaderboard, I can go spawn in my game again and I'll go and reset again. 50 00:03:07,040 --> 00:03:09,380 And as you can see, it increments to two. 51 00:03:10,700 --> 00:03:15,020 So now that we have our leaderboard complete and the next lecture, we're going to take a look at how 52 00:03:15,020 --> 00:03:19,910 to save some of the data in our leaderboard into a data store so we can grab that data when a player 53 00:03:19,910 --> 00:03:22,070 joins our game in a future session. 54 00:03:22,070 --> 00:03:23,270 See you there.